Skip to content

feat(sucrase): add support for jsxRuntime and other missing Sucrase options#1961

Open
vinny-silveira wants to merge 10 commits intorollup:masterfrom
vinny-silveira:master
Open

feat(sucrase): add support for jsxRuntime and other missing Sucrase options#1961
vinny-silveira wants to merge 10 commits intorollup:masterfrom
vinny-silveira:master

Conversation

@vinny-silveira
Copy link

Rollup Plugin Name: sucrase

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

(No specific issues found, but this PR adds support for options that already exist in Sucrase but were not exposed in the plugin.)

Description

This PR adds support for missing Sucrase options that were not being passed through to the transform function:

  • jsxRuntime - Enables the automatic JSX runtime (React 17+);
  • jsxImportSource - Custom JSX import source (e.g., preact);
  • preserveDynamicImport - Preserve dynamic import expressions;
  • injectCreateRequireForImportRequire - Inject createRequire for import.meta.

Additionally, this PR includes:

  1. Refactor: Simplified the resolveId function by removing a redundant ternary operator (the importer check guarantees it's always truthy at that point);
  2. Tests: Added a getBundle helper function to reduce boilerplate in tests, plus new tests for plugin initialization and the exclude filter;
  3. Documentation: Updated README.md to list all available Sucrase options.

Copilot AI and others added 4 commits February 12, 2026 18:50
Co-authored-by: vinny-silveira <13592890+vinny-silveira@users.noreply.github.com>
Remove redundant ternary in resolveId (importer is always truthy), extract common rollup setup into getBundle helper function and add tests for plugin initialization and exclude filter
…port

Add support for jsxRuntime and other missing Sucrase transform options
Copilot AI review requested due to automatic review settings February 13, 2026 13:09

This comment was marked as spam.

@shellscape
Copy link
Collaborator

Sorry about the copilot noise. I have no idea how that got turned on. But please disregard it.

@vinny-silveira
Copy link
Author

No worries at all, @shellscape! Totally understand, thanks for the heads-up. Happy to make any changes if needed.

@shellscape
Copy link
Collaborator

@CharlieHelps please do a thorough review of this PR to determine if it's ready to merge. Look at the diff, reviews, comments, and referenced issues/docs/links to build a complete understanding. Then respond with a comment that includes a list of MUST fix items that must be fixed before the the PR is merged, and a list of IMPROVEMENTS that shouldn't block the merge but may be quick improvements or things that could be addressed in a follow up PR. The MUST fix items should explain exactly what's wrong and what needs to change to resolve the problem. Both should be numbered lists and the IMPROVEMENTS list should continue counting up from the MUST list. It's OK if there are no IMPROVEMENTS or MUST fix items, you can just omit the lists.

@charliecreates
Copy link
Contributor

charliecreates bot commented Feb 16, 2026

I pulled the branch and ran the monorepo checks locally (pnpm install, prettier:check, build, lint:js, ci:coverage) — all green. The implementation change is small and looks correct: the new options are forwarded 1:1 to sucrase.transform, and the d.ts/README updates match upstream Sucrase option names (ref: https://github.com/alangpierce/sucrase/blob/main/src/Options.ts).

MUST fix

  1. packages/sucrase/test/test.js: getBundle() hard-codes context: 'this' for every Rollup bundle, which changes Rollup’s default top-level this semantics and is what drove the snapshot churn (__self: undefined__self: this). Unless there’s a specific reason the tests need this, please remove it (or make it opt-in per test) and update snapshots accordingly. If it is required, add a comment explaining why and scope it to only the affected tests.

IMPROVEMENTS
2. Add a small runtime assertion for jsxImportSource (e.g. jsxRuntime: "automatic", jsxImportSource: "preact") so we lock in that the plugin actually influences the emitted */jsx(-dev)-runtime import path.
3. Consider adding (or documenting) minimal coverage for preserveDynamicImport and injectCreateRequireForImportRequire — per Sucrase these are only meaningful with the imports transform / when not using it, so a short note in the README or a focused fixture test would prevent confusion.

Reverts the context: 'this' setting to align with Rollup's default behavior.
The context option was added to silence build warnings but has no impact
on the plugin's transformation logic. Snapshots updated accordingly.
…port

Address review feedback and improve test coverage
@vinny-silveira
Copy link
Author

Thanks for the thorough review, i really appreciate the detailed feedback.

I’ve addressed all the points you raised:

  • Rollup context handling: removed the hard-coded context: 'this' from getBundle(), restoring Rollup’s default top-level this semantics. Snapshots were updated accordingly;
  • jsxImportSource coverage: added a focused runtime assertion using jsxRuntime: "automatic" and a custom jsxImportSource to ensure the plugin effectively influences the emitted */jsx(-dev)-runtime import path;
  • preserveDynamicImport and injectCreateRequireForImportRequire: Added targeted tests for preserveDynamicImport and injectCreateRequireForImportRequire, ensuring these options behave as expected.

@vinny-silveira
Copy link
Author

Quick note on the Rollup context: 'this'

Just to explain the original rationale behind hard-coding context: 'this' in getBundle() (now removed per the review):

I initially added it to silence Rollup’s build-time warnings about top-level this being undefined in ES modules. This was purely a bundler-level configuration choice and has no impact on the plugin’s transformation logic — Sucrase operates entirely at transform time and never interacts with the runtime this value.

The snapshot change (__self: this vs __self: undefined) was simply a reflection of Rollup’s context setting rather than a behavioral change in the plugin itself. That said, I completely agree with keeping tests aligned with Rollup’s default semantics, so I’ve reverted the change and updated the snapshots back to undefined. The warnings were just noise during local runs, with no functional impact either way.

@shellscape
Copy link
Collaborator

That's fair, and Charlie doesn't always get reviews correct. If you feel that's worth pushing back on, you can revert your "fix" in reply to his review, and add a note in the source to the same effect as your comment above.

Add the context again to eliminate warnings during test execution.
@vinny-silveira
Copy link
Author

Thanks for the clarification — that makes sense.

I’ve reverted the removal and restored context: this, with an inline comment explaining the rationale. The intent is purely to keep test output clean by silencing Rollup’s top-level this warnings, especially as the test surface grows over time.

This remains a bundler-level concern only and doesn’t affect the plugin’s transform behavior in any way.

@shellscape
Copy link
Collaborator

@vinny-silveira are you using AI to reply to this PR?

@vinny-silveira
Copy link
Author

No. I only use Google Translate because my native language is Brazilian Portuguese, sorry if that sounds too formal.

@shellscape
Copy link
Collaborator

OK just checking because no humans use an emdash (—).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants